<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <link href="../../template/img/page-logo.png" rel="icon" type="image/png" />
    <title>IFE JavaScript Task 01</title>
  </head>
  
<body>

  <h3>污染城市列表</h3>
  <ul id="aqi-list">
<!--   
    <li>第一名：福州（样例），10</li>
  	<li>第二名：福州（样例），10</li> -->
  </ul>

<script type="text/javascript">

var aqiData = [
  ["北京", 90],
  ["上海", 50],
  ["福州", 10],
  ["广州", 50],
  ["成都", 90],
  ["西安", 100]
];

(function () {

  /*
  在注释下方编写代码
  遍历读取aqiData中各个城市的数据
  将空气质量指数大于60的城市显示到aqi-list的列表中
  */
  var ordinalCH = ["一", "二", "三", "四", "五", "六"];
  var aqiList = document.getElementById("aqi-list");
  aqiData.sort(function (a,b){
    return b[1] - a[1];     // 按从大到小排序
  });
  function createLi(city, ordinal){
    var newLi = document.createElement("li");
    newLi.innerHTML = "第"+ordinalCH[ordinal]+"名："+city[0]+"，"+city[1];
    return newLi;      
  }
  
  var list = []
  for (var i = 0; aqiData[i][1] > 60; i++){
      //list.add(createLi(aqiData[i], i+1));
      aqiList.appendChild(createLi(aqiData[i], i));
  }
  
  
})();

</script>
</body>
</html>